//
//  ZYSTagTableVC.m
//  budejie
//
//  Created by oldSix_Zhu on 16/9/1.
//  Copyright © 2016年 Dason. All rights reserved.
//

#import "ZYSTagTableVC.h"
#import "ZYSBtnHeaderModels.h"
#import "ZYSTagTableViewCell.h"

@interface ZYSTagTableVC ()

@property (nonatomic,strong)NSArray *tagArray;

@end

@implementation ZYSTagTableVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"标签贡献榜单";
    
    [self loadTagCell];
    
    
    [self createBtn];
}

-(void)createBtn
{
    //左边
    UIButton *btnL = [[UIButton alloc]init];
    
    [btnL setImage:[UIImage imageNamed:@"navigationButtonReturn"] forState:UIControlStateNormal];
    [btnL setImage:[UIImage imageNamed:@"navigationButtonReturnClick"] forState:UIControlStateHighlighted];
    
    [btnL setTitle:@"返回" forState:UIControlStateNormal];
    [btnL setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btnL setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    
    [btnL sizeToFit];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btnL];
    
    //点击事件
    [btnL addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
}

-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}


-(void)loadTagCell
{
    //Button头
    NSString *urlBtnStr = [NSString stringWithFormat:@"api_open.php?a=theme_users&appname=bs0315&asid=B9E7881C-C4F2-4996-9850-521DC65DAC49&c=topic&client=iphone&device=ios%%20device&from=ios&jbk=0&mac=&market=&openudid=2c1d53b0c26caba11781db5f9c3ebbb22c2864c0&sex=m&theme_id=%ld&udid=&uid=19183779&ver=4.3",self.theme_id];
    
    [ZYSBtnHeaderModels loadBtnHeaderWithUrlStr:urlBtnStr successBlock:^(NSArray *array) {
        
        self.tagArray = array;
        
//        NSLog(@"%@",array);
        
        [self.tableView reloadData];
        
    } failBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
    }];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tagArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"tagVCCellID";
    
    ZYSTagTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    if (cell == nil)
    {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"ZYSTagTableViewCell" owner:nil options:nil] lastObject];
    }
    
    ZYSBtnHeaderModels *model = self.tagArray[indexPath.row];
    
    cell.tagModel = model;
    
    return cell;
    
}


-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

@end







